package jp.ne.hatena.d.digitalsoul.warikan.pages

import java.text._
import java.util._

import org.apache.wicket.markup.html._
import org.apache.wicket.markup.html.basic._
import org.apache.wicket.markup.html.form._
import org.apache.wicket.markup.html.list._
import org.apache.wicket.model._

import jp.ne.hatena.d.digitalsoul.warikan.actions._
import jp.ne.hatena.d.digitalsoul.warikan.pages.forms._
import jp.ne.hatena.d.digitalsoul.warikan.pages.items._

class PlanningPage extends WebPage {
	
	val action = new PlanningAction
	
	val mainFormModel = new PlanningMainForm
	
	val participantListItems = new ArrayList[ParticipantListItem]
	
	val roles = action.createRoleList
	
	// form:main
	val main = new Form("main", new CompoundPropertyModel(mainFormModel))
	add(main)
	
	// text:name
	main.add(new TextField("partyName"))
	
	// text:schedule
	main.add(new TextField("schedule"))
	
	// text:location
	main.add(new TextField("location"))
	
	// table:participants
	val participants = new ListView[ParticipantListItem]("participants", participantListItems) {
		override def populateItem(listItem:ListItem[ParticipantListItem]) = {
			listItem.setModel(new CompoundPropertyModel(listItem.getModelObject))
			listItem.add(new TextField("name"))
			listItem.add(new DropDownChoice("role", roles))
		}
	}
	main.add(participants)
	
	// button:newLineButton
	val newLineButton = new Button("newLineButton") {
		override def onSubmit = {
			participantListItems.add(new ParticipantListItem)
		}
	}
	main.add(newLineButton)
	
	// button:cancelButton
	val cancelButton = new Button("cancelButton") {
		override def onSubmit = {
			setResponsePage(new TopPage)
		}
	}
	main.add(cancelButton)
	
	// button:commitButton
	val commitButton = new Button("commitButton") {
		override def onSubmit = {
			action.executePlanning(mainFormModel, participantListItems)
			setResponsePage(new TopPage)
		}
	}
	main.add(commitButton)

}